#include "Controller.h"

namespace catan
{

/*static*/ void Controller::handleActiveEvent(SDL_Event &event, bool &isActive)
{
	if (event.active.state & SDL_APPACTIVE)
	{
		isActive = (event.active.gain != 0);
	}
}

/*static*/ void Controller::handleVideoResize(SDL_Event &event, SDLCanvas &sdlCanvas, GLTextures &glTextures, GLContext &glContext)
{
	glTextures.dispose();
    if (sdlCanvas.resizeWindow(event.resize.w, event.resize.h))
	{
    	if (sdlCanvas.updateViewport())
    	{
			glTextures.create();
			glContext.reset();
    	}
	}
}

/*static*/ void Controller::handleKeyDown(SDL_Event &event, GameState &gameState)
{
	/*
    switch (event.key.keysym.sym)
	{
	case SDLK_ESCAPE:
	case SDLK_q:
	    gameState.end();
	    break;
	case SDLK_f:
		gameState.toggleFrame();
		break;
	case SDLK_m:
		gameState.toggleMask();
		break;
	case SDLK_h:
		gameState.toggleHexagons();
		break;
	case SDLK_b:
		gameState.toggleBackground();
		break;
	default:
	    break;
	}*/
	gameState.queueKeyDownEvent(event);
}

/*static*/ void Controller::handleMouseButtonDown(SDL_Event &event, GameState &gameState)
{
	gameState.queueMouseButtonDownEvent(event);
}

/*static*/ void Controller::handleMouseMotion(SDL_Event &event, GameState &gameState)
{
	gameState.queueMouseMotionEvent(event);
}

/*static*/ void Controller::handleQuit(GameState &gameState)
{
	gameState.end();
}

/*private*/ Controller::Controller()
{
}

}
